<?php
class ManagerController extends Controller {
    private $level = null;
    public function __construct() {
        parent::__construct();
        $this->viewFolder = 'manager/';
        $this->level = new LevelModel();
    }
    //管理员列表
    public function index() {
        parent::page();
        $this->tpl->assign('allManage',$this->model->findAll());
        $this->tpl->display(SMARTY_ADMIN.$this->viewFolder.'manager_list.tpl');
    }
    //添加管理员
    /************************************************************
    public function add() {
        if(isset($_POST['send'])){
            if($this->model->add()){
                $this->redirect->success('?c=manage','管理员新增成功！');
            } else {
                $this->redirect->failed('管理员新增失败！');
            }
        }
        $this->tpl->display(SMARTY_ADMIN.$this->viewFolder.'add.tpl');
    }
    */
    public function add() {
        $this->tpl->assign('allLevel',Tool::setFormItem($this->level->findAllNoPage(),'id','level_name'));
        $this->tpl->display(SMARTY_ADMIN.$this->viewFolder.'pop_add_manager.tpl');
    }
    public function addSubmit() {
        if($_GET['action'] == 'add'){
            echo $this->model->add() ? 'success' : 'failed';
        }
    }
    //ajax方式判断管理员用户名是否被占用
    public function isOneByAjax() {
        if(!empty($_GET)){
            echo $this->model->isOneByAjax() ? 'false' : 'true';
        }
    }
    //
    public function checkLevel() {
        if(!empty($_GET)){
            echo $this->model->checkLevel() ? 'false' : 'true';
        }
    }
    public function del() {
        if(isset($_GET['id'])){
            echo $this->model->del() ? 'success' : 'failed';
        }
    }
    public function update() {
        if(isset($_GET['id'])){
            $this->tpl->assign('allLevel',Tool::setFormItem($this->level->findAllNoPage(),'id','level_name'));
            $this->tpl->assign('oneManage',$this->model->findOne());
            $this->tpl->display(SMARTY_ADMIN.$this->viewFolder.'pop_update_manager.tpl');
        }
    }
    public function updateSubmit() {
        if(isset($_GET['id'])){
            if($this->model->update() !== false){
                echo 'success';
            }
        }
    }
    public function ajaxUpdate() {
        if(isset($_GET['id'])){
            if($this->model->ajaxupdate() !== false){
                echo 'success';
            }
        }
    }
}